﻿// Copyright (c) 2012-2013 fancidev
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Util.Media
{
    public abstract class ColorQuantizer
    {
        public abstract void Quantize(int[] pixels, int width, int height, int numColors);
    }

    public class PaletteEntryInfo
    {
        /// <summary>
        /// Gets the number of distinct colors in the color space represented
        /// by this color.
        /// </summary>
        public int ColorCount { get; /*protected*/ set; }

        /// <summary>
        /// Gets the number of pixels represented by this color.
        /// </summary>
        public int PixelCount { get; /*protected*/ set; }

        /// <summary>
        /// Gets a number that indicates the hierarchical level of this color
        /// entry. A smaller number indicates a higher level in the hierarchy,
        /// which corresponds to a larger color space. A value of 0 indicates
        /// the entire color space.
        /// </summary>
        public int Level { get; /*protected*/ set; }

        /// <summary>
        /// Gets the color of this palette entry.
        /// </summary>
        public Color Color { get; /*protected*/ set; }

        /// <summary>
        /// Gets the color that is used as a key (representative) of the color
        /// space covered by this entry. This may or may not be the actual 
        /// palette color.
        /// </summary>
        public Color KeyColor { get; /*protected*/ set; }

        /// <summary>
        /// Gets the 'average' color of the pixels represented by this color
        /// entry. This may or may not be the actual palette color.
        /// </summary>
        public virtual Color AverageColor { get; /*protected*/ set; }

        public override string ToString()
        {
            return string.Format(
                "L={0}, C={2}, P={1}",
                Level, PixelCount, ColorCount);
        }
    }
}
